#include "comm.h"

int main(int argc, char **argv)
{
    int msqid = create_msq();
    struct MsgType *msg = NULL;

    if(msqid < 0){
        return -1 ;
    }	

	msg = malloc(sizeof(struct MsgType));

    int i=0;
	while(i < atoi(argv[1])) 
	{
		msg->len = i;
		memset(msg->buf, 0, MAXSIZE);
		sprintf(msg->buf, "%d",(int)getpid());
		msg->x = (char)(i + 'a');
		msg->y = (short)(i + 100);

		printf("[CLIENT] pid=%d, msg->len = %d,msg->x = %c, msg->y = %d\n", (int)getpid(), msg->len, msg->x, msg->y);

		/*sending the message      --  mq_send() */
		if(msgsnd(msqid, (char*)msg, sizeof(struct MsgType), IPC_NOWAIT ) == -1)
		{
			perror("msgsnd() error");
			free(msg);
			return -1;
		}

		i++;
		sleep(1);   
	}
	free(msg);
	return 0;
}
